package org.colafries.metadata.query.impl;

import org.colafries.metadata.query.DBQuery;
import org.springframework.stereotype.Service;

/**
 * @author Ann
 * @version v1.0
 * @ClassName DamengQuery
 * @Description
 * @date Created in 2024/7/25
 **/
@Service(value = "damengQuery")
public class DamengQuery implements DBQuery {
    @Override
    public String schemaAllSql() {
        return "SELECT  DISTINCT  object_name TABLE_SCHEMA FROM all_objects WHERE  object_type='SCH' ";
    }

    @Override
    public String schemaName() {
        return "TABLE_SCHEMA";
    }

    @Override
    public String tablesSql(String schemaName) {
        return "SELECT DISTINCT object_name FROM all_objects WHERE object_type = 'TABLE' AND owner = '" + schemaName + "'";
    }

    @Override
    public String columnsSql(String schemaName, String tableName) {
        return "SELECT t.TABLE_NAME,t.COLUMN_NAME,t.DATA_TYPE,t.DATA_LENGTH,t.DATA_PRECISION,"
                + "t.DATA_SCALE,t.NULLABLE,t.CHAR_LENGTH,t.CHARACTER_SET_NAME,t.DATA_DEFAULT,t1.COMMENTS"
                + " FROM all_tab_columns t JOIN all_col_comments t1 "
                + " ON t.OWNER = t1.OWNER AND t.TABLE_NAME = t1.TABLE_NAME and t.COLUMN_NAME = t1.COLUMN_NAME "
                + " WHERE t.OWNER='" + schemaName + "' AND t.TABLE_NAME= '" + tableName + "'";
    }

    @Override
    public String tableName() {
        return "object_name";
    }

    @Override
    public String columnName() {
        return "COLUMN_NAME";
    }

    @Override
    public String columnType() {
        return "DATA_TYPE";
    }

    @Override
    public String precision() {
        return "DATA_PRECISION";
    }

    @Override
    public String columnComment() {
        return "COMMENTS";
    }

    @Override
    public String columnKey() {
        return null;
    }

    @Override
    public String isPK() {
        return null;
    }

    @Override
    public String columnLength() {
        return "CHAR_LENGTH";
    }

    @Override
    public String isNullable() {
        return "NULLABLE";
    }

    @Override
    public String nullableValue() {
        return null;
    }

    @Override
    public String characterSet() {
        return "CHARACTER_SET_NAME";
    }

    @Override
    public String collation() {
        return null;
    }

    @Override
    public String columnPosition() {
        return "DATA_PRECISION";
    }

    @Override
    public String scale() {
        return "DATA_SCALE";
    }

    @Override
    public String defaultValue() {
        return "DATA_DEFAULT";
    }

    @Override
    public String autoIncrement() {
        return null;
    }
}
